// pages/consultDoctor/consultDoctor.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    modalHidden:true,
    info:[],
    docid:0,
    is_buy:0,
    zi_list:[]
  },
  //确认
  modalBindaconfirm: function () {
    var id = this.data.info.id;
    wx.navigateTo({
      url: '../buy/buy?id='+id
    })
  },
  //取消
  modalBindcancel: function () {
    this.setData({
      modalHidden: true
    })
  },
  leftBindtap: function (e) {
    var that = this;
    if(that.data.is_buy == 1 || that.data.info.price == '0.00'){
      wx.navigateTo({
        url: '../perfection/perfection?id='+that.data.docid,
      })
    }else{
      that.setData({
        modalHidden: false
      })
    }
   
  },
  rightBindtap: function (e) {
    var that = this;
    if (that.data.is_buy == 1 || that.data.info.price == '0.00') {
      wx.makePhoneCall({
        phoneNumber: that.data.info.tel 
      })
    } else {
      that.setData({
        modalHidden: false
      })
    }
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this;
    var docid = options.id;
    that.setData({
      docid:docid
    });
    wx.request({
      url: app.d.ceshiUrl + '/Api/Doctor/details',
      method: "post",
      data: {
        docid: docid,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          that.setData({
            info: res.data.info
          });
        } else {
          wx.showToast({
            title: res.data.err,
          })
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 30000
        });
      },
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this;
    wx.request({
      url: app.d.ceshiUrl + '/Api/User/getcode',
      method: "post",
      data: {
        uid:app.d.userId,
        docid: that.data.docid,
      },
      header: {
        'Content-Type': 'application/x-www-form-urlencoded'
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          that.setData({
            is_buy: res.data.is_buy,
            zi_list: res.data.zi_list
          });
        } else {
          wx.showToast({
            title: res.data.err,
          })
        }
      },
      fail: function (e) {
        wx.showToast({
          title: '网络异常！',
          duration: 30000
        });
      },
    })
  },
  detail:function (e) {
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../searchRecord/searchRecord?id=' + id
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})